###1.字典


# 1.1 字典的创建

# d = dict()
# d["name"] = 'zs'
# d["age"] = 19


# 1.2字典的创建
# 字典的存储是无序的：索引不是递增的。
d = {"name": "zs", "age": 19}
d["name"] = "lisi"
# print(d)

# 1.3通过字典生成式来快速整合字典
key_list = ["name", "age", "age"]

value_list = ["zs", 19, 175]

# 然后通过字典关联两个列表
stu_dict = {k: v for k, v in zip(key_list, value_list)}
# print(stu_dict)


# 1.4判断某个key是否在字典中

# print(list(stu_dict.getkeys()))
#
# if "name" in stu_dict.keys():
#     print("该字典存在name key")

# 获取字典所有的值
# print(stu_dict.values())


# 同时获取Key-value的组合 ：item
# print(stu_dict.items())


# 读取字典中的键
# print(stu_dict["name"])
# stu_dict.get("name")

# update()增加键值对，将另一个字典的key-value添加到其中
# stu_dict.update({"k1": "v1", "k2": "v2"})


# 清空字典，保留内存地址
# stu_dict.clear()

# del  删除字典对象，内存地址回收
# del  stu_dict

# 弹出key对应的值，并删除该key
# print("===================")
# print(stu_dict.pop("name"))
# print(stu_dict)
#
# print("===================")
# print(stu_dict.popitem())


##遍历字典
# 方式一:遍历字典所有的key
#
# for x in stu_dict:
#     print(x)

# for x  in stu_dict.keys():
#     print(x)

# 方式二：遍历字典所有的值
# for k in stu_dict:
#     print(stu_dict[k])

# for  v in stu_dict.values():
#     print(v)


# 方式三：
# for item in stu_dict.items():
#     print(item)
#     print(f"字典的键{item[0]}对应的值“{item[1]}")


# 用字典推导式以字符串以及其import索引位置建字典
s_1 = ["import", "is", "with", "if", "file", "exception"]
d = {key: val for val, key in enumerate(s_1)}
# print(d)


# 弹出集合元素（从左至右)

#
# s1 = {1, 2, 3}
# s2 = {3, 4, 5, 2}
# # 交集
# print(s1 & s2)
# print(s1.intersection(s2))
# print(s1.intersection_update(s2))
#
# # 并集
# print(s1.union(s2))
#
# print(s1 | s2)
# # 差集
# print(s2 - s1)


list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
for i in range(0, len(list), 3):
    res = list[i:i + 3]
    # print(res)

#     import random
#     ranNum = random.choice(res)
# for j in range(len(ranNum)):
#     print(ranNum)






